<template>
  <div class="columns row row-cols-1 row-cols-md-4">
    <div class="col mb-10" v-for="list in listData" :key="list.id">
      <div class="card">
        <!-- <img :src="list.avatar && list.avatar.url ? list.avatar.url : defaultUrl" class="card-img-top" :alt="list.title" /> -->
        <div class="card-body">
          <h5 class="card-title">{{ list.title }}</h5>
          <p class="card-text">{{ list.description }}</p>
        </div>
        <button class="btn btn-primary" @click.prevent="goPages(list.code + '')"><i class="bi bi-house-fill"></i> 点击进入</button>
      </div>
    </div>
  </div>
</template>

<script lang="ts">
import { defineComponent, PropType, ref } from 'vue';
import imageUrl from '@/assets/default.png';
import { useRouter } from 'vue-router';
import { ColumnProps } from '@/store/types';
export interface ICellData {
  id: number;
  title: string;
  avatar?: string;
  description: string;
}

export default defineComponent({
  name: 'columns',
  props: {
    listData: {
      type: Array as PropType<ColumnProps[]>,
      required: true
    }
  },
  setup() {
    const router = useRouter();
    const defaultUrl = ref<string>(imageUrl);
    const goPages = (id: string) => {
      router.push({
        name: 'column',
        params: {
          cid: id
        }
      });
    };
    return { defaultUrl, goPages };
  }
});
</script>

<style lang="less" scoped>
.columns {
  flex-wrap: wrap;
  .col {
    .card {
      height: 300px;
      padding: 10px;
      justify-content: center;
      align-items: center;
      margin-bottom: 10px;
      img {
        width: 100px;
        height: 100px;
        border-radius: 10px;
      }
      .card-text {
        display: -webkit-box;
        -webkit-box-orient: vertical;
        -webkit-line-clamp: 3;
        overflow: hidden;
      }
    }
  }
}
</style>
